<?php
	session_start();
	
	function thisPage()
	{
		return $_SERVER["PHP_SELF"];
	}
	
	function isLogged()
	{
		if (isset($_SESSION["logged"]) && ($_SESSION["logged"])) return true; else return false;
	}
	
	
	function connectToDB()
	{
		require "sql_setup.php";
		if (!mysql_connect($server, $user, $password)) return false;
		if (!mysql_select_db($database)) return false;
		
		return true;
	}
	
	function tableLogin()
	{
		$table  = "\n\n<table border='1'><caption>Přihlašte se prosím:</caption>";
		$table .= "<tr><td>Uživatelské jméno</td><td><input type='text' name='nick'></td></tr>";
		$table .= "<tr><td>Heslo</td><td><input type='password' name='password'></td></tr>";
		$table .= "<tr><td colspan=2 style='text-align: right'><input type='submit' value='Přihlásit se'></td></tr>";
		$table .= "</table>\n\n";
		
		return $table;
	}
	
	
	
	
	/* Connection */
	if (!connectToDB())
	{
		echo "Error in DB";
		exit();
	}
	
		
	
	
	
?>
<!DOCTYPE html>
<html>
	<head>
		<title>Menstruační kalendář online</title>
		<meta charset="utf8">
		<link rel="stylesheet" media="screen" href="style.css">
	</head>
	<body>
		<div id="topbar">
		<div id="TopSection">
		<h1 id="sitename"><span><a href="<?php echo thisPage(); ?>">M</a></span><a href="<?php echo thisPage(); ?>">enstruační </a><span><a href="<?php echo thisPage(); ?>">k</a></span><a href="<?php echo thisPage(); ?>">alendář</a></h1>
		
		<div id="topbarnav"> 
			<span class="topnavitems"><a href="<?php echo thisPage(); ?>?registration=on">Registrace</a> | <a href="<?php echo thisPage(); ?>?login=on">Přihlášení</a></span>
			<!-- search zatím vypneme -->
			<!--			
			<form action="#"><div class="searchform">
		  		<label for="searchtxt">
		   		Search Terms:
			  	</label>
			  	<input class="keywordfield" id="searchtxt"/>
			  	<input type="submit" value="Search" />
			</div> 
			</form>
			-->
		</div>
		<div class="clear"></div>
		<ul id="topmenu">
		<li><a href="index.php">Hlavní stránka</a></li>
		<?php
			if (isLogged())
			{
			}
			else
			{
				?>
					<li><a href="index.php?login=on">Přihlásit se</a></li>
				<?php
			}
		?>
		
		
		<!-- takhle se dělá aktivní odkaz -->
		<!-- <li class="active"><a href="notes.html">Notes</a></li> -->
		</ul>
		</div>
		</div>
		
		<div id="wrap">
		
		<div id="contents">